package com.airline.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.airline.beans.Employee;
import com.airline.connection.AirlineSystemServiceProxy;
import com.airline.form.UpdateEmployeeForm;

public class UpdateEmployeeAction extends Action{
	
	AirlineSystemServiceProxy proxy = new AirlineSystemServiceProxy();
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		
		UpdateEmployeeForm empForm = (UpdateEmployeeForm)form;
		
		Employee emp = empForm.getEmp();
		
		boolean res = proxy.updateEmployee(emp);
		
		

		if (res == false) {

			empForm.setError("There is a duplicate employee record with these details");
			return mapping.findForward("failure");
		}
		
		//request.getSession().setAttribute("employee", emp);
		
		return mapping.findForward("success");
	}

}
